package com.kexio.common.exception;

/**
 * 基础异常类
 * 
 * 系统中所有自定义异常的基类
 * 
 * @author Kexio Team
 * @since 1.0.0
 */
public class BaseException extends RuntimeException {
    
    private static final long serialVersionUID = 1L;
    
    /** 错误码 */
    private int errorCode;
    
    /** 错误消息 */
    private String errorMessage;
    
    /** 错误详情（用于调试） */
    private Object errorDetails;
    
    // ==================== 构造函数 ====================
    
    public BaseException() {
        super();
    }
    
    public BaseException(String message) {
        super(message);
        this.errorMessage = message;
    }
    
    public BaseException(String message, Throwable cause) {
        super(message, cause);
        this.errorMessage = message;
    }
    
    public BaseException(Throwable cause) {
        super(cause);
    }
    
    public BaseException(int errorCode, String errorMessage) {
        super(errorMessage);
        this.errorCode = errorCode;
        this.errorMessage = errorMessage;
    }
    
    public BaseException(int errorCode, String errorMessage, Throwable cause) {
        super(errorMessage, cause);
        this.errorCode = errorCode;
        this.errorMessage = errorMessage;
    }
    
    public BaseException(int errorCode, String errorMessage, Object errorDetails) {
        super(errorMessage);
        this.errorCode = errorCode;
        this.errorMessage = errorMessage;
        this.errorDetails = errorDetails;
    }
    
    public BaseException(int errorCode, String errorMessage, Object errorDetails, Throwable cause) {
        super(errorMessage, cause);
        this.errorCode = errorCode;
        this.errorMessage = errorMessage;
        this.errorDetails = errorDetails;
    }
    
    // ==================== Getter 和 Setter ====================
    
    public int getErrorCode() {
        return errorCode;
    }
    
    public BaseException setErrorCode(int errorCode) {
        this.errorCode = errorCode;
        return this;
    }
    
    public String getErrorMessage() {
        return errorMessage;
    }
    
    public BaseException setErrorMessage(String errorMessage) {
        this.errorMessage = errorMessage;
        return this;
    }
    
    public Object getErrorDetails() {
        return errorDetails;
    }
    
    public BaseException setErrorDetails(Object errorDetails) {
        this.errorDetails = errorDetails;
        return this;
    }
    
    // ==================== toString ====================
    
    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append(getClass().getSimpleName());
        sb.append("{");
        sb.append("errorCode=").append(errorCode);
        sb.append(", errorMessage='").append(errorMessage).append('\'');
        if (errorDetails != null) {
            sb.append(", errorDetails=").append(errorDetails);
        }
        sb.append('}');
        return sb.toString();
    }
}
